package entity

import (
	"fmt"
	"time"

	"gorm.io/gorm"
	"shqsoft.cn/pas3ui/base"
)

//Zbdf
type Zbdf struct {
	ID   int       `gorm:"AUTO_INCREMENT;primary_key;column:ID"`
	DFJD time.Time `gorm:"column:DFJD"`
	DPID int       `gorm:"column:DPID"`
	ZBID int       `gorm:"column:ZBID"`
	ZBMC string    `gorm:"column:ZBMC"`
	DPNM string    `gorm:"column:DPNM"`
	DF   int       `gorm:"column:DF"`
}

//TableName
func (Zbdf) TableName() string {
	return "SH_JHCW_ZBDF"
}

func (s *Zbdf) BeforeSave(tx *gorm.DB) (err error) {
	jdint := datenfjj(s.DFJD)
	err = can_import(tx, jdint)
	if err != nil {
		return
	}
	err = tx.Raw(`SELECT "ID" FROM "T_Organization" WHERE "OrganName"=?`, s.DPNM).Row().Scan(&s.DPID)
	if err != nil || s.DPID == 0 {
		err = fmt.Errorf("机构名称%s在系统中不存在！", s.DPNM)
		return
	}
	err = tx.Raw(`select "ZBMC" from "SH_JHCW_JYDW_PERM" where "ZBID" = ?`, s.ZBID).Row().Scan(&s.ZBMC)
	return
}

func ZbdfEF() base.EntityFunc {
	return func() interface{} {
		entity := Zbdf{}
		return &entity
	}
}
func ZbdfESF() base.EntitiesFunc {
	return func() interface{} {
		var entities []Zbdf
		return &entities
	}
}

func init() {
	base.DaoPoolObj.Put("Zbdf", base.NewDefaultDao(ZbdfEF(), ZbdfESF(), nil, "my"))
}
